<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>OA登录</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/Login_css.css">
    <script rel="script" src="layui/layui.js"></script>
    <script rel="script" src="js/jquery-3.4.1.js"></script>
    <script rel="script" src="js/common.js"></script>
</head>
<body style="background-color: rgb(152,122,50)">
	<div class="wrap" style="background-image: url(img/login/backgound.png);background-repeat: no-repeat;background-position: center;">
		<div class="login-main">
			<div class="login-main2">
				<form class="layui-form" action="">
					<div class="login-title">
						<div align="center" style="padding-top: 30px;">
							<img src="img/login/logo.png" width="300px">
						</div>
						<div class="login-title-text">
							<span>欢迎登录</span>
						</div>
					</div>
					<div class="layui-form-item login-input">
						<div class="login-input-t">
							<i class="layui-icon login-in-i">&#xe66f;</i>
							<input id="user_name" class="login-title-username" placeholder="请输入用户名">
						</div>
						<div class="login-input-t">
							<i class="layui-icon login-in-i">&#xe673;</i>
							<input id="password" type="password" class="login-title-pwd" placeholder="请输入密码">
						</div>
						<div class="login-input-c">
							<div class="login-input-remeber" onclick="rememberMe()">
								<input id="chk_remember" type="checkbox" lay-skin="primary" class="login-input-check">
								<span class="login-input-check-text">记住密码</span>
							</div>
							<div class="login-input-forget">
								<a style="color: brown;">忘记密码</a>
							</div>
						</div>
						<div class="login-input-b">
							<input type="button" class="login-input-button layui-btn layui-btn-normal" value="登录" onclick="myLogin()">
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
<!-- 底部固定区域 -->
	<div class="layui-footer" style="text-align: center;font-size: 1.25rem;padding-top: 1.875rem;">
		© 物联网-大数据-李可
	</div>
<script>

	$(function () {
		//获取本地存储的用户名和密码
		var user_name = localStorage.getItem("user_name");
		var password = localStorage.getItem("password");
		//如果不为空就显示在页面上
		if(user_name != null && password != null){
			$("#user_name").val(user_name);
			$("#password").val(password);
			$("#chk_remember").attr("checked","checked");
		}
	});

    layui.use(['carousel', 'form'], function () {
        var carousel = layui.carousel
        var form = layui.form;
    });

	/**
	 * 登录方法
	 */
	function myLogin() {

		$.ajax({
			url:'/loginController/login.do',
			data:{
				user_name:$("#user_name").val(),
				password:$("#password").val()
			},
			dataType:'json',
			beforeSend: function () {

				//显示加载窗口
				toggleLoadingPanel(true);
			},
			success:function (result) {

				//关闭加载窗口
				toggleLoadingPanel(false);
			    var code = result.code;//状态码
			    if (code == 200){
			        //登录成功，跳转页面
					location.href = "jsp/index.jsp";
                } else{
			        //弹出提示框
                    layer.msg(result.msg);
                }
			}
		});
	}

	function rememberMe() {
		var isChecked = document.getElementById("chk_remember").checked;
		if (isChecked){
			localStorage.setItem("user_name",$("#user_name").val());
			localStorage.setItem("password",$("#password").val());
		} else {
			localStorage.removeItem("user_name");
			localStorage.removeItem("password");
		}
	}
</script>
</body>
</html>